//
//  HMNavigationController.swift
//  HMSlender
//
//  Created by 赵少朋赵少朋 on 17/1/17.
//  Copyright © 2017年 ITheima. All rights reserved.
//

import UIKit

class HMNavigationController: UINavigationController, UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        navigationBar.tintColor = UIColor.darkGray
        
        interactivePopGestureRecognizer?.delegate = self
        
    }
    
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        
        return childViewControllers.count != 1
    }
    
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
       
        
        
        var title:String?
        
            title = "返回"
        if childViewControllers.count > 0 {
         
            
            if childViewControllers.count == 1 {
                
                title = childViewControllers.first?.navigationItem.title ?? ""
                
                viewController.hidesBottomBarWhenPushed = true
                
            }
            
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imgName: "navigationbar_back_withtext", title: title, target: self, action:#selector(leftClick))
        }

         super.pushViewController(viewController, animated: animated)
        }
            
        

    func leftClick() {
    
         popViewController(animated: true)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
